package demo1223.pm;

import java.io.File;
import java.util.Scanner;

//在D盘查找包含输入的name字符的文件

public class Demo_02 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入:");
        String s = sc.next();
        File file = new File("D:\\");
        find(file, s);
    }

    public static void find(File file, String name) {
        if (file.isFile()) {
            String filename = file.getName().toLowerCase();
            if (filename.indexOf(name.toLowerCase()) != -1) {
                System.out.println(file.getPath());
            }
        } else {
            File[] files = file.listFiles();
            if (files==null){
                return;
            }
            for (File file1 : files) {
                find(file1, name);
            }

        }
    }
}
